(function() {
	window.xj = function(){};

	xj.log = function () {
		var a = window.console, b = arguments;
		if (a && a.log) {
			a.log.apply ? a.log.apply(a, b) : a.log(b);
		}
	}
	xj.ver = '20110228';
	/*
	获取一个唯一id
	*/
	xj.uniqueId = function () {
		return 'xj' + (_d++);
	};
	/*
	获取类型
	@obj {Object} 要获取的参数
	@return {String} 返回类型(该方法为增强的typeof)
	*/
	xj.getType = function (obj) {
		var type;
		return (type = typeof (obj)) == 'object' ? obj == null && 'null' || Object.prototype.toString.call(obj).slice(8, -1).toLowerCase() : type;
	};
	/*
	空方法
	*/
	xj.emptyFn = function () { };
	/* 
	中断 用于xj.each中
	*/
	xj.$break = 'break';
	/*
	用于xj.each 中
	*/
	xj.$continue = 'continue';
	/*
	常用方法
	*/
	xj.Lang = {
		/*
		判断参数是否为字符串
		@str {Obj} 参数
		@return {Boolean} 返回是否为字符串
		*/
		isString: function (obj) {
			return xj.getType(obj) == 'string';
		},
		/*
		判断参数是否为方法
		@obj {Object} 参数
		@return {Boolean} 返回是否为方法
		*/
		isMethod: function (obj) {
			return xj.getType(obj) == 'function';
		},
		/*
		判断参数是否为数组
		@obj {Object} 参数
		@return {Boolean} 返回是否为数组
		*/
		isArray: function (obj) {
			return xj.getType(obj) == 'array';
		},
		/*
            
		*/
		isUndefined: function (obj) {
			return xj.getType(obj) == 'undefined';
		},
		/*
            
		*/
		isNumber: function (obj) {
			return xj.getType(obj) == 'number';
		},
		/*
            
		*/
		isObject: function (obj) {
			return xj.getType(obj) == 'object';
		},
		/*
            
		*/
		is: function (test, aim) {
			var result;
			try {
				result = (aim == 'string' || xj.Lang.isString(aim)) ? xj.getType(test) == aim : test instanceof aim
			} catch (e) { };
			return !!result;
		},
		/*
		把给定的参数转换成数组
		@args {Object}
		@split {String}
		@return {Array}
		*/
		toArray: function (args, split) {
			if (!arguments.length) return [];
			if (!args || this.isString(args) || this.isUndefined(args.length)) {
				return (args + '').split(split ? split : '');
			}
			var result = [];
			for (var i = 0, j = args.length; i < j; i++) {
				result[i] = args[i];
			}
			return result;
		},
		/*
		依次尝试调用传入的方法
		@return 返回正确执行的方法的结果
		*/
		tryThese: function () {
			var a = arguments;
			for (var i = 0, j = a.length; i < j; i++) {
				try {
					return a[i]();
				} catch (ignore) {
				}
			}
			return false;
		},
		each: function (args, fn) {
			var L = xj.Lang, isFn = L.isMethod(fn);
			if (!isFn) return;
			if (L.isString(args)) args = L.toArray(args);
			if (!args) args = [];
			var isObj = L.isUndefined(args.length) || L.isMethod(args), i = 0;
			if (isObj) {
				for (var name in args) {
					try {
						fn(args[name], i++, name);
					} catch (e) {
						if (e == xj.$break) break;
						else if (e == xj.$continue) continue;
					}
				}
			} else {
				for (var j = args.length; i < j; i++) {
					try {
						fn(args[i], i, args[i]);
					} catch (e) {
						if (e == xj.$break) break;
						else if (e == xj.$continue) continue;
					}
				}
			}
		},
		/*
		判断两个数组的内容是否相等
		*/
		arrEqual: function (a1, a2) {
			var l;
			if (this.isArray(a1) && this.isArray(a2) && (l = a1.length) == a2.length) {
				for (var i = 0; i < l; i++) if (!this.arrEqual(a1[i], a2[i])) return false;
				return true
			}
			return a1 === a2;
		},
		/*
		获取XMLHTTPRequest
		*/
		getXMLReq: function () {
			return window.XMLHttpRequest ? new (XMLHttpRequest) : new ActiveXObject('Microsoft.XMLHTTP');
		},
		/*
		清除页面选择区域
		*/
		clearPageSelection: function () {
			this.tryThese(function () {
				window.getSelection().removeAllRanges()
			}, function () {
				document.selection.empty()
			}, function () {
				document.selection = Q
			});
		}
	};
	/*
	创建一个类
	@cls {Object} 方法集合
	@base {Object} 基类
	@reutnr {Function} 新类
	*/
	xj.createClass = function (cls, base) {
		var f = function () {
			this.init.apply(this, arguments)
		};
		var a = {};
		var y = {};
		cls = xj.Lang.isMethod(cls) ? (a = function () { }, a.prototype = cls.prototype, new a) : cls || a;
		base = xj.Lang.isMethod(base) ? base(a.prototype || cls) : base;
		xj.extend(y, cls);
		xj.extend(y, base || {});
		y.init = y.$ || y.init || function () { };
		f.prototype = y;
		return f
	};
})();